//
//  HHViewController.m
//  HHAVPlayer
//
//  Created by hh1016 on 01/19/2022.
//  Copyright (c) 2022 hh1016. All rights reserved.
//

#import "HHViewController.h"
#import <HHAVPlayer/HHAVPlayerHeader.h>
#import <HHBlockKit/HHBlockHeader.h>
#import <Masonry/Masonry.h>

@interface HHViewController ()

@end

@implementation HHViewController{
    HHPlayerView *_playerView;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
//    HHPlayerView *playerView = [[HHPlayerView alloc]init];
//    [self.view addSubview:playerView];
//    [playerView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.view).offset(20);
//        make.left.right.equalTo(self.view);
//        // 注意此处，宽高比16：9优先级比1000低就行，在因为iPhone 4S宽高比不是16：9
//        make.height.equalTo(playerView.mas_width).multipliedBy(9.0f/16.0f).with.priority(750);
//    }];
    NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"history" ofType:@".mov"];
//
//    playerView.videoURL = [NSURL fileURLWithPath:videoPath];
////    playerView.videoURL = [NSURL URLWithString:@"http://oos-cn.ctyunapi.cn/sxct.yjy/video/%E9%A1%B6%E9%83%A8%E8%A7%86%E9%A2%91.mov?Signature=3hTV53NmhETWrb9KxYIcNDm270s%3D&AWSAccessKeyId=9c2495884b213186018d&Expires=88021995361"];
////    [playerView setViewName:@"history" andType:@".mov"];
//    _playerView = playerView;
//    _playerView.isRepeatPlay = YES;
    
    UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:but];
    but.frame = CGRectMake(100, 400, 100, 100);
    but.backgroundColor = UIColor.cyanColor;
    [but addTarget:self action:@selector(butClicked) forControlEvents:UIControlEventTouchUpInside];
    
    HHPlayerNoControlView *playerNoView = [[HHPlayerNoControlView alloc]init];
    [self.view addSubview:playerNoView];
    [playerNoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(0);
        make.left.right.equalTo(self.view);
        // 注意此处，宽高比16：9优先级比1000低就行，在因为iPhone 4S宽高比不是16：9
        make.height.equalTo(playerNoView.mas_width).multipliedBy(9.0f/16.0f).with.priority(750);
    }];

    playerNoView.isRepeatPlay = YES;
    playerNoView.videoURL =  [NSURL fileURLWithPath:videoPath];

}
- (void)butClicked{
    HHPlayerViewController *playerVC = [[HHPlayerViewController alloc]init];
    NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"history" ofType:@".mov"];
    playerVC.videoURL = [NSURL fileURLWithPath:videoPath];
    playerVC.isRepeatPlay = YES;
    playerVC.seekTime = 5;
    [self presentViewController:playerVC animated:YES completion:nil];
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
        self.view.backgroundColor = [UIColor whiteColor];
        //if use Masonry,Please open this annotation
        
        [_playerView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view).offset(20);
        }];
         
        
    }else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
        self.view.backgroundColor = [UIColor blackColor];
        //if use Masonry,Please open this annotation
        
        [_playerView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.view).offset(0);
        }];
         
    }

}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}




@end
